package org.stvd.common.utils;

import java.io.Serializable;

/**
 * @Title: ServiceResult
 * @Description 后台业务统一处理类
 * @author houzx
 * @date 2020年10月21日
 */
public class ServiceResult<T> implements Serializable {

    private static final long serialVersionUID = 4949377569141535657L;

    /** 业务执行返回代码 {0：默认成功}*/
    private String code = "0";
    
    /** 业务执行是否成功 {true：默认成功；false：失败}*/
    private boolean success = true;
  
    /** 业务返回信息*/
    private String message = "请求成功";
    
    /** 业务返回结果*/
    private T result = null;
    
    
    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getResult() {
        return result;
    }

    public void setResult(T result) {
        this.result = result;
    }

    public void setParamError() {
        this.code = "10000";
        this.success = false;
        this.message = "参数错误";
    }
    
    public void setParamError(String message) {
        this.code = "10000";
        this.success = false;
        this.message = message;
    }
    
    public void setDataError() {
        this.code = "20000";
        this.success = false;
        this.message = "数据错误";
    }
    
    public void setDataError(String message) {
        this.code = "20000";
        this.success = false;
        this.message = message;
    }
    
    public void setSystemError() {
        this.code = "90000";
        this.success = false;
        this.message = "系统错误";
    }
    
    public void setSystemError(String message) {
        this.code = "90000";
        this.success = false;
        this.message = message;
    }
    
    /* (non-Javadoc)
     * @see java.lang.Object#toString()
     */
    @Override
    public String toString() {
        return "ServiceResult [result=" + result + ", success=" + success + ", message=" + message + ", code=" + code
                + "]";
    }
}
